﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FacadeSingTowerMall;
using DTOSingTowerMall;
using System.Web.Security;
using System.IO;


namespace WebFormSingTowerMall
{
    public partial class EventBookingDetails : HallBookingBaseController
    {

        protected override void Page_Load(object sender, EventArgs e)
        {


            base.Page_Load(sender, e);
            currentPage = "EventBookingDetails.aspx";

            if (!IsPostBack)
            {
                HallIDTxtBx.Text = Convert.ToString(bookingDetails.hallId);
                HallNameTxtBx.Text = Convert.ToString(bookingDetails.hallName);
                StartDateTxBx.Text = Convert.ToString(bookingDetails.eventStartDate);
                EndDateTxBx.Text = Convert.ToString(bookingDetails.eventEndDate);
            }
        }

        protected void StartDateImgBtn_Click(object sender, ImageClickEventArgs e)
        {
            StartDateCalendar.Visible = true;
        }

        protected void EndDateImgBtn_Click(object sender, ImageClickEventArgs e)
        {
            EndDateCalendar.Visible = true;

        }
        protected void StartDateCalendar_SelectionChanged(object sender, EventArgs e)
        {
            StartDateCalendar.Visible = false;
            StartDateTxBx.Text = StartDateCalendar.SelectedDate.ToShortDateString();
            
        }
        protected void EndDateCalendar_SelectionChanged(object sender, EventArgs e)
        {
            EndDateCalendar.Visible = false;
            EndDateTxBx.Text = EndDateCalendar.SelectedDate.ToShortDateString();
            
        }

        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            bookingDetails.hallId = Convert.ToInt32(HallIDTxtBx.Text);

            bookingDetails.eventTitle = EventTitleTxtBx.Text;
            bookingDetails.eventDesc = EventDescTxtBx.Text;
            bookingDetails.eventStartDate = Convert.ToDateTime(StartDateTxBx.Text);
            bookingDetails.eventEndDate = Convert.ToDateTime(EndDateTxBx.Text);
            //int hallId = Convert.ToInt32( HallIDTxtBx.Text);
            //string hallName = HallNameTxtBx.Text;
            //string eventTitle = EventTitleTxtBx.Text;
            //string eventDesc = HallDescTxtBx.Text;
            //DateTime startDate = Convert.ToDateTime (StartDateTxBx.Text);
            //DateTime endDate = Convert.ToDateTime (EndDateTxBx.Text);
            //string imgPath = UploadImgTxBx.Text;


            //EventHallBookingFacade feventHallBkg = new EventHallBookingFacade();
           // feventHallBkg.fBookEventHall( hallId,  hallName,  eventTitle,  eventDesc,  startDate,  endDate,  imgPath);

            NextPage();
        }

        protected void StartDateCalendar_SelectionChanged1(object sender, EventArgs e)
        {
            StartDateCalendar.Visible = false;
            StartDateTxBx.Text = StartDateCalendar.SelectedDate.ToShortDateString() + " " + StartDateCalendar.SelectedDate.ToShortTimeString();
        }

        protected void EndDateCalendar_SelectionChanged1(object sender, EventArgs e)
        {
            EndDateCalendar.Visible = false;
            EndDateTxBx.Text = EndDateCalendar.SelectedDate.ToShortDateString() + " " + EndDateCalendar.SelectedDate.ToShortTimeString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                try
                {
                    if
                    (FileUpload1.PostedFile.ContentType == "image/jpeg")
                    {
                        if
                        (FileUpload1.PostedFile.ContentLength < 1028000)
                        {
                            string filename = Path.GetFileName(FileUpload1.FileName);
                            FileUpload1.SaveAs(Server.MapPath("~/EventImages/") + filename);
                            lblStatusMessage.Text = "File uploaded successfully!";
                        }
                        else

                            lblStatusMessage.Text = "File maximum size is 1 MB";
                    }
                    else

                        lblStatusMessage.Text =
                        "Only JPEG files are accepted!";
                }
                catch (Exception exc)
                {
                    lblStatusMessage.Text =
                    "The file could not be uploaded. The following error occured: "
                    + exc.Message;
                }
            }
            else
            {
                lblStatusMessage.Text = "Please select the file";
            }
        }





    }
}